#pragma once
#include "ISceneNodeTerrain2D.h"
#include "CVector3.h"
#include "CTransform.h"
#include "CSprite.h"
#include "CRenderBatchManager.h"
#include "WareEngineNameSpace.h"

BEGIN_WARE

class ITexture;
class IResourceManager;

class CTerrainSprite : public CSprite
{
public:
	CTerrainSprite() : CSprite(0) {}

	virtual void	GetWorldTransform( CMatrix4& matWorld );
	virtual float32 GetCameraSpaceDepth();

	void			SetZWrite( VBOOL bZWriteEnable );

	void			SetWorldTrans( CTransform& Trans )	{ m_Transform = Trans; }

private:

	CTransform		m_Transform;
};

class CTerrain2D : public ISceneNodeTerrain2D
{
public:
	CTerrain2D( uint32 uID );
	~CTerrain2D(void);

	typedef map< uint32, CTerrainSprite* > SpriteMap;

	virtual int32					GetEntityType()		{ return ENTITYNODE_TERRAIN; };

	virtual ISceneNodeTransform*	GetParent()			{ return m_pParent; }

	virtual void					CullVisibleObjects( ISceneNodeCamera* pCamera );

	virtual void					SetParent( ISceneNodeTransform* pNode )	{ m_pParent = pNode; }

	virtual void					SetWireFrameMode( VBOOL bWireFrame )	{ m_bWireFrameMode = bWireFrame; }

	virtual void					SetVisible( VBOOL bVisible )	{ m_bVisible = bVisible; }
	virtual VBOOL					IsVisible()						{ return m_bVisible; }

	virtual int32					Grab() { return 0; }
	virtual int32					Drop();

	virtual uint32					GetID()							{ return m_uID; }


	virtual VBOOL					Update( IGraphic* pGraphic, uint32 uCurTime );
	virtual VBOOL					Render( IGraphic* pGraphic, uint32 uCurTime );

	virtual ITexture*				GetTexture();
	virtual void					SetTexture( ITexture* pTexture );

	VBOOL							CreateWithTexture( int32 nMapWidth, int32 nMapHeight, int32 nGridWidth, int32 nGridHeight, ITexture* pTexture );
	VBOOL							CreateFromFile( const VCHAR* szTerrainCfg );
	void							Destroy();

private:

	uint32							m_uID;
	ISceneNodeTransform*			m_pParent;
	ITexture*						m_pTexture;

	int32							m_nMapWidth;
	int32							m_nMapHeight;

	VBOOL							m_bVisible;
	VBOOL							m_bWireFrameMode;
	SpriteMap						m_mapSprite;
};

END_WARE
